package com.sas.web.articles;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.ResourceModel;

import com.sas.domain.Article;
import com.sas.model.EntityModel;
import com.sas.web.BasePage;
import com.sas.web.panel.articles.ArticleInfoPanel;

public class ArticleSinglePage extends BasePage { 

	public ArticleSinglePage(IModel<Article> defaultModelObject,
			final ModalWindow modal1) {
		
		Form<Article> form = new Form<Article>("form", new CompoundPropertyModel<Article>(new EntityModel<Article>(Article.class, defaultModelObject.getObject())));
		final ArticleInfoPanel aip = new ArticleInfoPanel("articleInfo");
		aip.setEnable(false);
		form.add(aip);
		final AjaxButton save = new AjaxButton("save", new ResourceModel("save"), form) {
			
			/**
			 * 
			 */
			private static final long serialVersionUID = 6460064140609159975L;

			@Override
			protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
				modal1.close(target);
			}
		};
		
		form.add(new Button("edit", new ResourceModel("edit")) {
			/**
			 * 
			 */
			private static final long serialVersionUID = -6425609159933791571L;

			@Override
			public void onSubmit() {
				aip.setEnable(true);
				save.setEnabled(true);
			}
		});

		save.setEnabled(false);
		form.add(save);
		
		FeedbackPanel feedback = new FeedbackPanel("feedback");
		add(feedback);
		add(form);
		
		
	}
//	@SuppressWarnings("serial")
//	public ArticleSinglePage(Article article) {
//		
//		Form<Article> form = new Form<Article>("form", new CompoundPropertyModel<Article>(new EntityModel<Article>(Article.class, article)));
//		final ArticleInfoPanel aip = new ArticleInfoPanel("articleInfo");
//		aip.setEnable(false);
//		form.add(aip);
//		final Button save = new Button("save", new ResourceModel("save")) {
//			@Override
//			public void onSubmit() {
//				
//			}
//		};
//		
//		form.add(new Button("edit", new ResourceModel("edit")) {
//			@Override
//			public void onSubmit() {
//				aip.setEnable(true);
//				save.setEnabled(true);
//			}
//		});
//
//		save.setEnabled(false);
//		form.add(save);
//		
//		FeedbackPanel feedback = new FeedbackPanel("feedback");
//		add(feedback);
//		add(form);
//	}
//
//	public ArticleSinglePage(Article article, final ModalWindow modal1) {
//		Form<Article> form = new Form<Article>("form", new CompoundPropertyModel<Article>(new EntityModel<Article>(Article.class, article)));
//		final ArticleInfoPanel aip = new ArticleInfoPanel("articleInfo");
//		aip.setEnable(false);
//		form.add(aip);
//		final AjaxButton save = new AjaxButton("save", form) {
//			
//			@Override
//			protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
//				modal1.close(target);
//			}
//		};
//		
//		
//		form.add(new Button("edit", new ResourceModel("edit")) {
//			@Override
//			public void onSubmit() {
//				aip.setEnable(true);
//				save.setEnabled(true);
//			}
//		});
//
//		save.setEnabled(false);
//		form.addOrReplace(save);
//		
//		FeedbackPanel feedback = new FeedbackPanel("feedback");
//		add(feedback);
//		add(form);
//	}


}
